package test;

//有效的数独：https://leetcode.cn/problems/valid-sudoku/
public class IsValidSudoku {
	public boolean[][] row;
    public boolean[][] col;
    public boolean[][][] grid;
    public boolean isValidSudoku(char[][] board) {
        row=new boolean[9][10]; //第i行的中1-9是否存在
        col=new boolean[9][10]; //第i列中的1-9是否存在
        grid=new boolean[3][3][10]; 
        for(int i=0;i<9;i++){
            for(int j=0;j<9;j++){
                if(board[i][j]!='.'){
                    if(row[i][board[i][j]-'0']==true||
                       col[j][board[i][j]-'0']==true||
                       grid[i/3][j/3][board[i][j]-'0']==true){
                        return false;
                    }
                    row[i][board[i][j]-'0']=true;
                    col[j][board[i][j]-'0']=true;
                    grid[i/3][j/3][board[i][j]-'0']=true;
                }
            }
        }
        return true;
    }
}
